﻿using MsTestUtilities.Utilities;
using System;

namespace MsTestUtilities.RowTests
{
    internal class AsserterExpectation<E> : IExpectation<E>
    {
        private readonly Func<E, E, AssertionResult> _asserter;
        private readonly E _expected;

        public AsserterExpectation(E expected, Func<E, E, AssertionResult> asserter)
        {
            _expected = expected;
            _asserter = asserter;
        }

        public AssertionResult IsSatisfiedFor(Func<E> actualGenerator)
        {
            try
            {
                return _asserter(_expected, actualGenerator());
            }
            catch (Exception ex)
            {
                return AssertionResult.Error("An unexpected exception was trown: {0}", ex);
            }
        }
    }
}
